package com.miyu.system.utils.enumeration;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * system 统一返回数据封装 使用当前返回提示信息
 * code 业务编码
 * msg 返回信息
 * status 提示状态码
 * @author miyu
 * @date 2022/10/25
 */
@Getter
@ToString
@AllArgsConstructor
public enum Result {
    /** 成功 */
    SUCCESS("10001", "操作成功",1),
    /** 错误 */
    ERROR("10002", "操作失败",-1);
    private final  String code;
    private final String msg;
    private final Integer status;

    public static JSONObject getInfoByCode(String code) {
        JSONObject result = new JSONObject();
        for (Result s : values()) {
            if (s.getCode().equals(code)) {
                result.put("code",s.getCode());
                result.put("msg",s.getMsg());
                result.put("status",s.getStatus());
                break;
            }
        }
        return result;
    }
}
